﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bass.Tools;
using MySql.Data.MySqlClient;

public partial class admin_admin_add_notice : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["adminname"]) == "")
        {
            Response.Write("<script language=javascript>alert('您没有登录');window.parent.document.location.href ='admin_login.aspx'</script>");
        }
        else if (Convert.ToString(Session["adminkind"]) != "product")
        {
            Response.Write("<script language=javascript>alert('您不是产品管理员，无权访问此页！');location='admin_login.aspx'</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //OleDbConnection Conn = new OleDbConnection();
        //Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../miumiu.mdb");
        //Conn.Open();

        //取到连接字符串
        string propertiesPath = Server.MapPath("../mysqldb.properties");
        mytools mt = new mytools();
        string ConnString = mt.getMysqlConn(propertiesPath);

        //打开连接
        MySqlConnection myConnection = new MySqlConnection(ConnString);
        myConnection.Open();

        string title = this.noticetitle.Text.ToString();
        string content = this.noticecontent.Text.ToString();
        DateTime dt = Convert.ToDateTime(DateTime.Now);
        string addtime = dt.ToString("yyyyMMddHHmmss");
        string addadminname = Convert.ToString(Session["adminname"]);
        string noticeid = addadminname + addtime;

        MySqlCommand Comm = new MySqlCommand("insert into notice_info values ('" + noticeid + "','" + title + "','" + content + "','" + addadminname + "','" + addtime + "')", myConnection);
        Comm.ExecuteNonQuery();
        myConnection.Close();
        Response.Write("<script lanuage=javascript>alert('" + addadminname + "  发布公告成功!');location='admin_add_notice.aspx'</script>");
    }
}
